<template>
  <div>
    <el-card>
      <el-form style="width: 400px;margin: 10px">
        <el-form-item label="用户名">
          <el-input v-model="form.username"  autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="昵称">
          <el-input v-model="form.nickName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input v-model="form.age" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input v-model="form.sex" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="form.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="update">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>

import request from "@/utils/request";

export default {
  name: "Person",
  data() {
    return {
      form: {},
    }
  },
  created() {
    let str = sessionStorage.getItem("user")||"{}"
      this.form = JSON.parse(str);
  },
  methods: {
    update() {
      request.put("/user", this.form).then(res => {
        if (res.code === '0') {
          this.$message({
            type:"success",
            message:"更新成功"
          })
          sessionStorage.setItem("user",JSON.stringify(this.form))
        } else {
          this.$message(
              {
                type:"error",
                message:res.msg
              }
          )
        }
      })
    },

  }
}
</script>

<style>

</style>